﻿using Koala.Pro.Common;
using Koala.Pro.Core;
using Koala.Pro.Core.Dto;
using Koala.Pro.Core.Models;
using SqlSugar;

namespace Koala.Pro.Services
{
    public class SystemTypeService : MyCrudService<SystemTypeInfo, string, SystemTypePagedDto>, ISystemTypeService, IMyCrudService<SystemTypeInfo, string, SystemTypePagedDto>, ITransientDependency, IDependency
    {
        public SystemTypeService(IApiUserSession currentApiUser)
        {
            base.CurrentApiUser = currentApiUser;
        }

        public override Task<Dictionary<string, string>> GetColumnNameAlias()
        {
            return Task.FromResult(new Dictionary<string, string>
        {
            { "Oid", "系统标识" },
            { "Name", "系统名称" },
            { "CustomID", "客户编码" },
            { "Authorize", "授权编码" },
            { "Note", "备注" }
        });
        }

        protected override ISugarQueryable<SystemTypeInfo> CreateFilteredQueryAsync(SystemTypePagedDto input)
        {
            return base.CreateFilteredQueryAsync(input).WhereIF(!input.ExcludeId.IsNullOrWhiteSpace(), (SystemTypeInfo t) => t.Id != input.ExcludeId).WhereIF(!input.Id.IsNullOrWhiteSpace(), (SystemTypeInfo t) => t.Id.Contains(input.Id))
                .WhereIF(!input.Name.IsNullOrWhiteSpace(), (SystemTypeInfo t) => t.Name.Contains(input.Name))
                .WhereIF(!input.CustomID.IsNullOrWhiteSpace(), (SystemTypeInfo t) => t.CustomID.Contains(input.CustomID))
                .WhereIF(!input.Authorize.IsNullOrWhiteSpace(), (SystemTypeInfo t) => t.Authorize.Contains(input.Authorize))
                .WhereIF(!input.Note.IsNullOrWhiteSpace(), (SystemTypeInfo t) => t.Note.Contains(input.Note));
        }

        protected override ISugarQueryable<SystemTypeInfo> ApplyDefaultSorting(ISugarQueryable<SystemTypeInfo> query)
        {
            return query.OrderBy((SystemTypeInfo s) => s.Id);
        }
    }
}
